package com.example.service;

import com.example.entity.Params;
import com.example.entity.Good;
import com.example.mapper.GoodMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodService {
    @Autowired
    private GoodMapper goodMapper;


    public List<Good> findAll() {
        return goodMapper.selectAll();
    }


    public PageInfo<Good> findBySearch(Params params) {
        PageHelper.startPage(params.getPageNum(), params.getPageSize());


        List<Good> list = goodMapper.findBySearch(params);

        return PageInfo.of(list);
    }

    public void add(Good good) {
        goodMapper.add(good);
    }

    public void update(Good good) {
        goodMapper.update(good);
    }


    public void delete(Integer id) {

        goodMapper.deleteById(id);
    }

    public Good selectById(Integer id) {
        return goodMapper.selectById(id);
    }


    public void updateById(Good good) {
        goodMapper.update(good);
    }

}
